<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form size="mini" :model="pageData" layout="inline" v-if="permissionStore.hasPermisson('cgdsh.cx1')">
            <a-form-item label="采购单号">
              <!-- <a-select popup-container="html"  class="bacClass" :loading="loadings6" @search="handleSearch6" v-model="pageData.dropDownData"
                                                          :filter-option="false" allow-search allow-clear @focus="focusSel6">
                                                    <a-option v-for="item in pageData.nameLists6 as any" :value="item.purchaseCode">{{
                                                        item.purchaseCode
                                                        }}</a-option>
                                                </a-select> -->
              <a-input class="bacClass" placeholder="" v-model="pageData.dropDownData" @press-enter="huiche"
                allow-clear />
            </a-form-item>
          </a-form>
        </div>
        <div>
          <Toolbar :items="[
            `${permissionStore.hasPermisson('cgdsh.cx1') ? '查询' : ''}`,
            `${permissionStore.hasPermisson('cgdsh.sh1') ? '审核' : ''}`,
            `${permissionStore.hasPermisson('cgdsh.bh1') ? '驳回' : ''}`,
          ]" @select="selectSh" @audit="auditSh" @rejected="rejecteds">
          </Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18" />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div class="my-tool-bar">
        <!-- <Toolbar :items="['查询', '删除','导出']" @export="exports" @del="deleteHandler" @select="selectSh" @audit="auditSh"
                                                @rejected="rejecteds"></Toolbar> -->
        <!-- <Toolbar :items="['查询', '审核', '驳回']" @select="selectSh" @audit="auditSh" @rejected="rejecteds">
                                        </Toolbar> -->
      </div>
    </template>
    <template #pageTabel>
      <!-- <a-tabs   :justify="true">
                                        <a-tab-pane title="采购列表"> -->

      <!-- <a-table size="mini" :scrollbar="true" sticky-header :style="{
                                                height: pageData.rHeight + 80 + 'px'
                                            }" @page-change="pagination.change" stripe :bordered="true" :columns="tableColumns"
                                                :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
                                                v-model:selected-keys="selectedRowKeys" :loading="table.tableLoading" :data="table.dataList"
                                                :pagination="false" :rowKey="rowKey">

                                                <template #auditState="{ record }">
                                                    <a-button v-if="record.auditState == 0" type="primary" status="warning" disabled
                                                        size="mini">待审核
                                                    </a-button>
                                                    <a-button v-if="record.auditState == 1" status="success" disabled size="mini">审核通过
                                                    </a-button>
                                                    <a-space v-if="record.auditState == 2">
                                                        <a-button type="primary" status="danger" disabled size="mini">审核驳回</a-button>
                                                        <a-button type="primary" @click="auditStates(record)" size="mini">反审</a-button>
                                                    </a-space>
                                                </template>
                                                <template #cz="{ record }">
                                                    <a-button v-if="record.auditState == 0" type="primary" size="mini" status="warning"
                                                        @click="editHandler(record)">
                                                        <template #icon>
                                                            <icon-edit />
                                                        </template>
                                                        修 改
                                                    </a-button>
                                                    <a-button v-else disabled type="primary" size="mini" status="warning"
                                                        @click="editHandler(record)">
                                                        <template #icon>
                                                            <icon-edit />
                                                        </template>
                                                        修 改
                                                    </a-button>
                                                    <a-button type="primary" size="mini" style="margin-left: 5px;" @click="cxDetails(record)">
                                                        详情
                                                    </a-button>
                                                </template>
                                            </a-table> -->
      <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
        <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady"
          style="height: 100%" :defaultColDef="defaultColDef" class="ag-theme-alpine" :rowData="table.dataList"
          :columnDefs="tc" :localeText="localeText1"></AgGridVuesCopys>
      </a-spin>
      <a-drawer style="z-index: 999" ok-text="保存" cancel-text="关闭" :drawer-style="{ zIndex: 999 }" :width="400"
        popup-container=".arco-tabs-content" height="100%" placement="bottom" :visible="visibles" unmountOnClose
        @cancel="isCancel" @ok="isOk">
        <template #title> 修改采购单 </template>
        <div style="width: 1540px; overflow: auto; padding-right: 5px" class="scrollbar">
          <el-scrollbar>
            <a-form ref="formRef" layout="horizontal" :model="dataForm" :label-col-props="{ span: 11 }"
              :wrapper-col-props="{ span: 13 }" size="mini">
              <a-row>
                <a-col>
                  <a-form-item label="采购订单" field="purchaseCode" :rules="[{ required: true, message: '采购订单必填' }]"
                    :validate-trigger="['change', 'blur']">
                    <a-input disabled placeholder="" v-model="dataForm.purchaseCode" class="bacClass" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="编制日期" field="purchaseDate" :rules="[{ required: true, message: '日期必填' }]"
                    :validate-trigger="['change', 'blur']">
                    <a-date-picker  popup-container="html"  class="bacClass" style="width: 13.5rem"
                      :time-picker-props="{ defaultValue: '00:00:00' }" format="YYYY-MM-DD"
                      v-model="dataForm.purchaseDate" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="供应商名称" field="providerId" :rules="[{ required: true, message: '供应商名称必填' }]"
                    :validate-trigger="['change', 'blur']">
                    <a-select popup-container="html"  class="bacClass" :loading="loading" @change="proChange" @search="handleSearchz"
                      v-model="dataForm.providerId" :filter-option="false" allow-search allow-clear @focus="focusSelz">
                      <a-option v-for="item in pageData.nameListz as any" :value="item.id">
                        {{ item.providerName }}</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="采购类型" field="purchaseType" :rules="[{ required: true, message: '采购类型必填' }]"
                    :validate-trigger="['change', 'blur']">
                    <a-select popup-container="html"  class="bacClass" :loading="loading" @search="handleSearchs" v-model="dataForm.purchaseType"
                      :filter-option="false" allow-search allow-clear @focus="focusSels">
                      <a-option v-for="item in pageData.nameLists as any" :value="item.purchaseType">{{
                        item.purchaseType
                      }}</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="采购员" field="createName">
                    <a-input v-model="dataForm.createName" disabled class="bacClass" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="付款方式">
                    <a-select popup-container="html"  class="bacClass" :loading="loadingx" @search="handleSearchx"
                      v-model="dataForm.settlementType" :filter-option="false" allow-search allow-clear
                      @focus="focusSelx">
                      <a-option v-for="item in pageData.nameList as any" :value="item.settlementName">
                        {{ item.settlementName }}</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row class="grid-demo">
                <a-col>
                  <a-form-item label="交货方式">
                    <a-select popup-container="html"  class="bacClass" :loadingqq="loading" @search="handleSearchqq"
                      v-model="dataForm.logisticType" :filter-option="false" allow-search allow-clear @focus="focusSelqq">
                      <a-option v-for="item in pageData.nameListqq as any" :value="item.deliveryType">
                        {{ item.deliveryType }}</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="计划交货日期" field="planDeliveryDate" :rules="[{ required: true, message: '日期必填' }]"
                    :validate-trigger="['change', 'blur']">
                    <a-date-picker  popup-container="html"  class="bacClass" style="width: 13.5rem"
                      :time-picker-props="{ defaultValue: '00:00:00' }" format="YYYY-MM-DD"
                      v-model="dataForm.planDeliveryDate" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="结算公司" field="settlementCompanyName" :rules="[{ required: true, message: '结算公司必填' }]"
                    :validate-trigger="['change', 'blur']">
                    <a-input class="bacClass" placeholder="" v-model="dataForm.settlementCompanyName" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="签订地点">
                    <a-input class="bacClass" placeholder="" v-model="dataForm.signAddress" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="制单人" field="createName">
                    <a-input disabled v-model="dataForm.createName" class="bacClass" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="交货说明">
                    <a-input class="bacClass" placeholder="" v-model="dataForm.deliveryExplain" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row class="grid-demo">
                <a-col>
                  <a-form-item label="采购公司">
                    <a-cascader @change="casaders" :options="xqOptions" v-model="dataForm.useCompany"
                      :style="{ width: '22rem' }" allow-clear popup-container="html"/>
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="采购部门" field="useDepartment" :rules="[{ required: true, message: '采购部门必填' }]"
                    :validate-trigger="['change', 'blur']">
                    <a-select popup-container="html"  class="bacClass" v-model="dataForm.useDepartment" :style="{ width: '22rem' }" allow-clear>
                      <a-option v-for="item in zjArrays1[0].children">{{ item.label }}</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="备注" field="remark">
                    <a-input class="bacClass" v-model="dataForm.remark" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="合同号">
                    <a-input class="bacClass" placeholder="" v-model="dataForm.orderNo" />
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item label="币种" field="moneyType" :rules="[{ required: true, message: '币种必填' }]"
                    :validate-trigger="['change', 'blur']">
                    <a-select popup-container="html"  class="bacClass" placeholder="" v-model="dataForm.moneyType" allow-clear @focus="focusBl">
                      <a-option v-for="item in pageData.blTypeList" :value="item['detailName']">{{
                        item['detailName']
                      }}</a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col>
                  <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="送货地址" field="address"
                    :validate-trigger="['change', 'blur']" :rules="[{ required: true, message: '送货地址必填' }]">
                    <a-select popup-container="html"  class="bacClass" v-model="dataForm.address" @search="searchAddress" @focus="focusAddress"
                      allow-clear allow-search :filter-option="false">
                      <a-option v-for="item in pageData.dzList" :value="item['detailName']">{{ item['detailName'] }}
                      </a-option>
                    </a-select>
                  </a-form-item>
                </a-col>
              </a-row>
            </a-form>
          </el-scrollbar>
        </div>
        <a-space :style="{
          marginBottom: '10px',
        }">
          <a-button type="primary" @click="tqxqd">提取申购单</a-button>
          <!-- <a-button type="outline" @click="tjWl">添加申购信息</a-button> -->
          <a-button type="outline" @click="scWl">删除</a-button>
        </a-space>
        <a-table :scrollbar="true" sticky-header stripe :bordered="true" :columns="tableColumns1" :data="isDataLists"
          v-model:selected-keys="selectedRowKeys1" row-key="applyCode"
          :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }">
          <template #purchaseNum="{ record }">
            <a-input class="bacClass" v-model="record.purchaseNum" placeholder="" allow-clear />
          </template>
          <template #price="{ record }">
            <a-input class="bacClass" v-model="record.price" placeholder="" allow-clear />
          </template>
          <template #amount="{ record }">
            <a-input class="bacClass" v-model="record.amount" placeholder="" allow-clear />
          </template>
          <template #taxMoney="{ record }">
            <a-input class="bacClass" v-model="record.taxMoney" placeholder="" allow-clear />
          </template>
        </a-table>
      </a-drawer>
      <!-- 
                                        </a-tab-pane>
                                    </a-tabs> -->
    </template>
    <paginationCopys :page-size-options="pagingList1" :total="pagination.total" show-total show-jumper show-page-size
      @change="PageSize" @page-size-change="change1" style="justify-content: center" :page-size="pagination.pageSize"
      :current="pagination.page" />
    <a-modal width="100rem" v-model:visible="visible" @cancel="visible = false" @ok="handleBeforeOk">
      <template #title> 提取申购单 </template>
      <div class="xqdxx">
        <a-form size="mini" :model="pageData" layout="inline">
          <a-form-item label="申购单号">
            <a-select popup-container="html"  class="bacClass" :style="{ width: '320px' }" :loading="loading" placeholder=""
              @search="handleSearchqqq" v-model="pageData.dropDownDataqqq" :filter-option="false" allow-search allow-clear
              @focus="focusSelqqq">
              <a-option v-for="item in pageData.nameListqqq" :value="item.applyCode">{{
                item.applyCode
              }}</a-option>
            </a-select>
          </a-form-item>
        </a-form>
        <Toolbar :style="{ width: '100px' }" :items="['查询']" @select="selectShs"></Toolbar>
      </div>
      <a-table size="mini" :scrollbar="true" sticky-header height="100%" @page-change="pagination1.change" stripe
        :bordered="true" :columns="tableColumnsq" :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
        v-model:selected-keys="selectedRowKeys" :loading="tables.tableLoading" :data="tables.dataList"
        :pagination="pagination1" rowKey="applyCode">
        <template #confirmState="{ record }">
          <a-button v-if="record.confirmState == 0" type="primary" status="danger" disabled>未确认
          </a-button>
          <a-button v-if="record.confirmState == 1" status="success" disabled>已确认</a-button>
          <!-- <span v-if="record.confirmState == 0">未确认</span>
                                                     <span v-if="record.confirmState == 1">已确认</span> -->
        </template>
        <template #auditState="{ record }">
          <a-button v-if="record.auditState == 0" type="primary" status="warning" disabled>待审核
          </a-button>
          <a-button v-if="record.auditState == 1" status="success" disabled>审核通过</a-button>
          <a-button v-if="record.auditState == 2" type="primary" status="danger" disabled>审核驳回
          </a-button>
          <!-- <span v-if="record.auditState == 0">待审核</span>
                                                     <span v-if="record.auditState == 1">审核通过</span>
                                                     <span v-if="record.auditState == 2">审核驳回</span> -->
        </template>
      </a-table>
    </a-modal>
    <!-- 修改弹窗 -->
    <a-drawer ok-text="保存" cancel-text="关闭" :drawer-style="{ zIndex: 999 }" :width="400"
      popup-container=".arco-tabs-content" height="100%" placement="bottom" :visible="visibles1" unmountOnClose
      @cancel="isCancel" @ok="isOk1">
      <template #title> 修改采购单 </template>
      <div style="width: 1540px; overflow: auto; padding-right: 5px" class="scrollbar">
        <el-scrollbar>
          <a-form ref="formRef" layout="inline" size="mini" :model="dataForm" :label-col-props="{ span: 11 }"
            :wrapper-col-props="{ span: 13 }">
            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="结算公司" field="settlementCompanyName"
              :rules="[{ required: true, message: '结算公司必填' }]" :validate-trigger="['change', 'blur']">
              <!-- <a-select popup-container="html"  class="bacClass" :loading="loading2" v-model="dataForm.settlementCompanyName"
                        @focus="foucusUseFrim(1)" @search="handleSearch2" :filter-option="false">
                        <a-option v-for="item of pageData.firmList" :value="item['firmName']">
                          {{ item.typeName }}{{ item.typeName == '' ? '' : '-' }}{{ item.firmName }}
                        </a-option>
                      </a-select> -->
              <a-cascader v-model="dataForm.settlementCompanyName" :options="pageData.firmGroupList1" allow-clear
                ref="casOb2" @change="cascaderChange2($event, dataForm.settlementCompanyName)" class="bacClass"
                :title="pageData.title2"   :loading="pageData.loading2" popup-container="html"/>
            </a-form-item>
            <!-- <a-form-item :style="{width:'320px'}" label-col-flex="120px" label="采购订单">
                                                        <a-input disabled :style="{ width: '13.5rem' }" v-model="dataForm.purchaseCode" />
                                                      </a-form-item> -->

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="编制日期" field="purchaseDate" disabled>
              <a-date-picker  popup-container="html"  style="width: 13.5rem" :time-picker-props="{ defaultValue: '00:00:00' }" format="YYYY-MM-DD"
                v-model="dataForm.purchaseDate" class="bacClass" />
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="供应商名称" field="providerId"
              :rules="[{ required: true, message: '供应商名称必填' }]" :validate-trigger="['change', 'blur']">
              <a-select popup-container="html"  class="bacClass" :style="{ width: '13.5rem' }" :loading="loading" @search="handleSearchz"
                @change="proChange" v-model="dataForm.providerId" :filter-option="false" allow-search allow-clear
                @focus="focusSelz">
                <a-option v-for="item in pageData.nameListz" :value="item.id">{{
                  item.providerName
                }}</a-option>
              </a-select>
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="采购类型" field="purchaseType"
              :rules="[{ required: true, message: '采购类型必填' }]" :validate-trigger="['change', 'blur']">
              <a-select popup-container="html"  class="bacClass" :style="{ width: '13.5rem' }" :loading="loading" @search="handleSearchs"
                v-model="dataForm.purchaseType" :filter-option="false" allow-search allow-clear @focus="focusSels">
                <a-option v-for="item in pageData.nameLists as any" :value="item.purchaseType">{{
                  item.purchaseType
                }}</a-option>
              </a-select>
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="采购员" field="createName">
              <a-input :style="{ width: '13.5rem' }" v-model="dataForm.createName" disabled class="bacClass" />
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="结算方式">
              <a-select popup-container="html"  class="bacClass" :style="{ width: '13.5rem' }" :loading="loadingx" p @search="handleSearchx"
                v-model="dataForm.settlementType" :filter-option="false" allow-search allow-clear @focus="focusSelx">
                <a-option v-for="item in pageData.nameList as any" :value="item.settlementName">{{
                  item.settlementName
                }}</a-option>
              </a-select>
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="交货方式">
              <a-select popup-container="html"  class="bacClass" :style="{ width: '13.5rem' }" :loadingqq="loading" @search="handleSearchqq"
                v-model="dataForm.logisticType" :filter-option="false" allow-search allow-clear @focus="focusSelqq">
                <a-option v-for="item in pageData.nameListqq" :value="item.deliveryType">{{
                  item.deliveryType
                }}</a-option>
              </a-select>
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="计划交货日期" field="planDeliveryDate"
              :rules="[{ required: true, message: '日期必填' }]" :validate-trigger="['change', 'blur']">
              <a-date-picker  popup-container="html"  class="bacClass" style="width: 13.5rem" :time-picker-props="{ defaultValue: '00:00:00' }"
                format="YYYY-MM-DD" v-model="dataForm.planDeliveryDate" />
            </a-form-item>

            <!-- <a-form-item
                                                     :style="{width:'355px'}" label-col-flex="120px"
                                                        label="结算公司"
                                                        field="settlementCompanyName"
                                                        :rules="[{ required: true, message: '结算公司必填' }]"
                                                        :validate-trigger="['change', 'blur']"
                                                      >
                                                 
                                                        <a-select popup-container="html" 
                                                          class="bacClass"
                                                          :loading="loading2"
                                                          v-model="dataForm.settlementCompanyName"
                                                          @focus="foucusUseFrim(1)"
                                                          @search="handleSearch2"
                                                          :filter-option="false"
                                                        >
                                                          <a-option v-for="item of pageData.firmList" :value="item['firmName']">
                                                            {{ item.typeName }}{{ item.typeName == '' ? '' : '-' }}{{ item.firmName }}
                                                          </a-option>
                                                        </a-select>
                                                      </a-form-item> -->
            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="采购单号">
              <a-input disabled :style="{ width: '13.5rem' }" v-model="dataForm.purchaseCode" class="bacClass" />
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="签订地点" field="signAddress"
              :validate-trigger="['change', 'blur']">
              <a-input class="bacClass" :style="{ width: '13.5rem' }" v-model="dataForm.signAddress" />
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="制单人" field="createName">
              <a-input disabled :style="{ width: '13.5rem' }" v-model="dataForm.createName" class="bacClass" />
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="交货说明" field="deliveryExplain"
              :validate-trigger="['change', 'blur']">
              <a-input class="bacClass" :style="{ width: '13.5rem' }" v-model="dataForm.deliveryExplain" />
            </a-form-item>

            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="采购公司" field="useCompany"
              :rules="[{ required: true, message: '采购公司必填' }]" :validate-trigger="['change', 'blur']">
              <a-cascader v-model="dataForm.useCompany" :options="pageData.firmGroupList" allow-clear ref="casOb"
                @change="cascaderChange($event, dataForm.useCompany)" :title="pageData.title"  
                :loading="pageData.loading" disabled class="bacClass" popup-container="html"/>
            </a-form-item>

            <!-- <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="采购部门" field="useDepartment"
                :rules="[{ required: true, message: '采购部门必填' }]" :validate-trigger="['change', 'blur']">
                <a-cascader v-model="dataForm.useDepartment" :options="pageData.bmList" allow-clear ref="casOb1"
                  @change="cascaderChange1" :title="pageData.title1"   :loading="pageData.loading1"
                  disabled />
              </a-form-item> -->
            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="合同号" field="orderNo"
              :validate-trigger="['change', 'blur']">
              <a-input class="bacClass" :style="{ width: '13.5rem' }" v-model="dataForm.orderNo" />
            </a-form-item>
            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="币种" field="moneyType"
              :rules="[{ required: true, message: '币种必填' }]" :validate-trigger="['change', 'blur']">
              <a-select popup-container="html"  class="bacClass" :style="{ width: '13.5rem' }" v-model="dataForm.moneyType" allow-clear
                @focus="focusBl">
                <a-option v-for="item in pageData.blTypeList" :value="item['detailName']">{{
                  item['detailName']
                }}</a-option>
              </a-select>
            </a-form-item>
            <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="送货地址" field="address"
              :validate-trigger="['change', 'blur']" :rules="[{ required: true, message: '送货地址必填' }]">
              <a-select popup-container="html"  class="bacClass" v-model="dataForm.address" @search="searchAddress" @focus="focusAddress"
                allow-clear allow-search :filter-option="false">
                <a-option v-for="item in pageData.dzList" :value="item['detailName']">{{ item['detailName'] }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item :style="{ width: '1490px' }" label-col-flex="120px" label="备注" field="remark">
              <a-textarea class="bacClass" v-model="dataForm.remark" allow-clear show-word-limit />
            </a-form-item>
          </a-form>
          <!-- <a-table :scrollbar="true" sticky-header @page-change="pagination1.change" stripe :bordered="true"
                                                            :columns="tableColumns3" v-model:selected-keys="selectedRowKeys1" :loading="table.tableLoading"
                                                            :data="pageData.tqDataList" :pagination="pagination1" rowKey="uid" size="mini">

                                                            <template #purchaseNum="{ record }">
                                                                <a-input class="bacClass" -number v-model="record.purchaseNum" class="input-demo" :min="0"
                                                                    :max="10000000000000000000" />
                                                            </template>
                                                            <template #stockNum="{ record }">
                                                                <a-input class="bacClass" -number v-model="record.stockNum" class="input-demo" :min="0"
                                                                    :max="10000000000000000000" />
                                                            </template>

                                                            <template #remark="{ record }">
                                                                <a-input class="bacClass"  v-model="record.remark" />
                                                            </template>
                                                        </a-table> -->
          <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 99%; z-index: 999">
            <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReadysz111"
              style="height: 500px" :defaultColDef="defaultColDefsz111" class="ag-theme-alpine"
              :rowData="pageData.tqDataList" :columnDefs="tcsz111"></AgGridVuesCopys>
          </a-spin>
        </el-scrollbar>
      </div>
    </a-drawer>
    <a-modal v-model:visible="visible1" title="采购单详情" :width="1200" :footer="false" :draggable="true">
      <a-table :style="{
        height: '100%',
        marginTop: '10px',
      }" stripe :bordered="true" :scrollbar="true" sticky-header :columns="tableColumns3"
        :data="pageData.isDetailsList">
      </a-table>
    </a-modal>

    <a-modal v-model:visible="visible5" title="系统提示" :draggable="true">
      <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="是否驳回订单?"></a-form-item>
      <a-form-item :style="{ width: '355px' }" label-col-flex="120px" label="驳回原因：">
        <a-input class="bacClass" allow-clear v-model="dataForm.rejectCause"></a-input>
      </a-form-item>
      <template #footer>
        <el-button @click="visible5 = false">取消</el-button>
        <el-button type="primary" @click="okk1">确认</el-button>
      </template>
    </a-modal>
    <a-modal v-model:visible="visible6" title="系统提示" :draggable="true">
      <a-form-item label="是否驳回物料?"></a-form-item>
      <a-form-item label="驳回原因：">
        <a-input class="bacClass" allow-clear v-model="dataForm.rejectCause"></a-input>
      </a-form-item>
      <template #footer>
        <el-button @click="visible6 = false">取消</el-button>
        <el-button type="primary" @click="okk">确认</el-button>
      </template>
    </a-modal>
  </pageTabelLayout>
</template>

<script setup lang="ts" >
import { reactive, ref, onMounted } from 'vue'
import { post } from '@/api/http'
import { Form, Message, Modal } from '@arco-design/web-vue'
import { useTable, useRowKey, useTableColumn, usePagination, useRowSelection } from '@/hooks/table'
import emitter from '@/hooks/useEventBus'
import PostType from '@/views/organizational/PostType.vue'
import XqService from '../orderpurchase/service/xq/index'

import { localeText } from '@/api/aggridZw'
import { pagingList } from '@/api/paging'
import usePermission from '@/store/modules/permission'
import { slicing } from '@/utils/caseFrimAndSecRig'
const { selectedRowKeys, onSelectionChange } = useRowSelection()
const rowKey = useRowKey('id')
const pagination = usePagination(doRefresh)
const pagination1 = usePagination(doRefreshs)
const table = useTable()
const tables = useTable()
const formRef = ref()

const XqServices = new XqService()
const xqOptions = XqServices.xqArrays
const zjArrays = XqServices.zjArray
let zjArrays1: any = ref([
  {
    children: [{ label: '' }],
  },
])
const casaders = (val: any) => {
  dataForm.useDepartment = ''
  zjArrays1.value = zjArrays.value.filter((res: any) => {
    return val == res.value
  })
  if (dataForm.useCompany !== '' && dataForm.useCompany !== undefined) {
    let list = pageData.firmListsy.filter(function (o: any) {
      return o['id'] == dataForm.useCompany
    })
    dataForm.useCompanyName = list[0]['typeName']
      ? list[0]['typeName'] + '-' + list[0]['firmName']
      : list[0]['firmName']
  }
}
function change1(val: any) {
  pagination.pageSize = val
  doRefresh()
}

function PageSize(val: any) {
  pagination.page = val
  doRefresh()
}
const tableColumnsq = useTableColumn([
  {
    title: '申购单号',
    key: 'applyCode',
    dataIndex: 'applyCode',
    width: 150,
  },
  // {
  //     title: "物料编号",
  //     key: "purchaseNeedCode",
  //     dataIndex: "purchaseNeedCode",
  //     width: 150
  // },
  {
    title: '物料名称',
    key: 'materialName',
    dataIndex: 'materialName',
    width: 150,
  },
  {
    title: '申购数量',
    key: 'applyNum',
    dataIndex: 'applyNum',
    width: 150,
  },
  {
    title: '已采购',
    key: 'purchasedAlready',
    dataIndex: 'purchasedAlready',
    width: 150,
  },
  {
    title: '未采购',
    key: 'notPurchased',
    dataIndex: 'notPurchased',
    width: 150,
  },
  // {
  //     title: "物料编号",
  //     key: "updateTime",
  //     dataIndex: "updateTime",
  //     width: 150
  // },
  {
    title: '申购类型',
    key: 'applyType',
    dataIndex: 'applyType',
    width: 150,
  },
  {
    title: '申购部门',
    key: 'applyDepartment',
    dataIndex: 'applyDepartment',
    width: 150,
  },
  {
    title: '申购人',
    key: 'applyPerson',
    dataIndex: 'applyPerson',
    width: 150,
  },
  {
    title: '采购部门',
    key: 'useDepartment',
    dataIndex: 'useDepartment',
    width: 150,
  },
  {
    title: '采购单号',
    key: 'applyCode',
    dataIndex: 'applyCode',
    width: 150,
  },
  {
    title: '状态',
    key: 'auditState',
    dataIndex: 'auditState',
    slotName: 'auditState',
    width: 150,
    fixed: 'right',
  },
  {
    title: '审核人',
    key: 'auditPerson',
    dataIndex: 'auditPerson',
    width: 150,
  },
  {
    title: '审核日期',
    key: 'auditDate',
    dataIndex: 'auditDate',
    width: 150,
  },
  {
    title: '修改人',
    key: 'updateName',
    dataIndex: 'updateName',
    width: 150,
  },
  {
    title: '修改日期',
    key: 'updateTime',
    dataIndex: 'updateTime',
    width: 150,
  },
  {
    title: '备注',
    key: 'remark',
    dataIndex: 'remark',
    width: 150,
  },
  // {
  //     title: "审核人",
  //     key: "auditPerson",
  //     dataIndex: "auditPerson",
  //     width: 150
  // },
  // {
  //     title: "审核时间",
  //     key: "auditDate",
  //     dataIndex: "auditDate",
  //     width: 150
  // },
  // {
  //     title: "修改人",
  //     key: "updateName",
  //     dataIndex: "updateName",
  //     width: 150
  // }

  // {
  //     title: '操作',
  //     key: 'id',
  //     slotName: 'action',
  //     width: 150, fixed: 'right'
  // }
])

let visibles = ref(false)
let visibles1 = ref(false)
let visible = ref(false)
const tqxqd = () => {
  visible.value = true
}
const scWl = () => {
  if (selectedRowKeys1.value.length == 0) {
    Message.error('请选择要删除的数据')
    return
  }
  if (selectedRowKeys1.value.length > 1) {
    // isDataLists.value.forEach((item:any,index:any)=>{
    //     selectedRowKeys1.value.forEach((items:any,indexs:any)=>{
    //         if(item.materialName == items){
    //             isDataLists.value.splice(index,1)
    //             selectedRowKeys1.value.splice(indexs,1)
    //         }
    //     })
    // })
    selectedRowKeys1.value.forEach((item: any, index: any) => {
      console.log(item)
      isDataLists.value.forEach((items: any, indexs: any) => {
        if (item == items.applyCode) {
          // selectedRowKeys1.value.splice(index,1)
          isDataLists.value.splice(indexs, 1)
        }
      })
    })
    if (selectedRowKeys1.value.length > isDataLists.value.length) {
      selectedRowKeys1.value = []
    }
  } else {
    isDataLists.value.some((item: any, index: any) => {
      if (selectedRowKeys1.value == item.applyCode) {
        isDataLists.value.splice(index, 1)
        selectedRowKeys1.value = []
      }
    })
  }
}

let isDataLists: any = ref([])
let selectedRowKeys1 = ref([])

const handleBeforeOk = () => {
  if (selectedRowKeys.value.length == 0) {
    visible.value = true
    Message.error('请勾选数据')
    return
  }
  selectedRowKeys.value.forEach((item: any) => {
    tables.dataList.forEach((items: any) => {
      if (item == items.applyCode) {
        isDataLists.value.push({
          applyCode: items.applyCode,
          materialName: items.materialName,
          specName: items.specName,
          batchName: items.batchName,
          unit: items.unit,
          applyNum: items.applyNum,
          purchaseNum: items.applyNum,
          price: items.price,
          amount: items.amount,
          taxMoney: items.taxMoney,
        })
      }
    })
  })
}

function doRefresh() {
  pageData.pageLoading = true
  post({
    url: 'dwPurchase/PurchaseOrder/getPage',
    data: {
      page: pagination.page,
      size: pagination.pageSize,
      auditState: 0,
      purchaseCode: pageData.dropDownData,
      selectType: 0,
    },
  })
    .then(({ data, code }: any) => {
      if (code === 200) {
        table.handleSuccess(data.list)
        pagination.setTotalSize(data.total)
        gridOption.value.setRowData(data.list)
      }
    })
    .catch(console.log)
    .finally(() => {
      pageData.pageLoading = false
    })
}

const tableColumns1 = useTableColumn([
  {
    title: '申购单号',
    key: 'applyCode',
    dataIndex: 'applyCode',
    width: 150,
  },
  {
    title: '物料名称',
    key: 'materialName',
    dataIndex: 'materialName',
    width: 150,
  },
  {
    title: '规格',
    key: 'specName',
    dataIndex: 'specName',
    width: 150,
  },
  // {
  //     title: "批次",
  //     key: "batchName",
  //     dataIndex: "batchName",
  //     width: 150
  // },
  {
    title: '单位',
    key: 'unit',
    dataIndex: 'unit',
    width: 150,
  },
  {
    title: '申购数量',
    key: 'applyNum',
    dataIndex: 'applyNum',
    width: 150,
  },
  {
    title: '采购数量',
    key: 'purchaseNum',
    dataIndex: 'purchaseNum',
    slotName: 'purchaseNum',
    width: 150,
  },
  {
    title: '单价',
    key: 'price',
    dataIndex: 'price',
    slotName: 'price',
    width: 150,
  },
  {
    title: '金额',
    key: 'amount',
    dataIndex: 'amount',
    slotName: 'amount',
    width: 150,
  },
  {
    title: '税率',
    key: 'taxMoney',
    dataIndex: 'taxMoney',
    slotName: 'taxMoney',
    width: 150,
  },
])

const tableColumns2 = useTableColumn([
  {
    title: '物料编号',
    key: 'materialCode',
    dataIndex: 'materialCode',
    width: 150,
  },
  {
    title: '物料名称',
    key: 'materialName',
    dataIndex: 'materialName',
    width: 150,
  },
  {
    title: '规格',
    key: 'specName',
    dataIndex: 'specName',
    width: 150,
  },
  // {
  //     title: "批次",
  //     key: "batchName",
  //     dataIndex: "batchName",
  //     width: 150
  // },
  {
    title: '单位',
    key: 'unit',
    dataIndex: 'unit',
    width: 150,
  },

  // {
  //     title: "需求数量",
  //     key: "needNum",
  //     dataIndex: "needNum",
  //     width: 150
  // },
  {
    title: '申购单数量',
    key: 'applyNum',
    dataIndex: 'applyNum',
    slotName: 'applyNum',
    width: 150,
  },
  {
    title: '采购数量',
    key: 'purchaseNum',
    dataIndex: 'purchaseNum',
    slotName: 'purchaseNum',
    width: 150,
  },
  {
    title: '库存数量',
    key: 'stockNum',
    dataIndex: 'stockNum',
    slotName: 'stockNum',
    width: 150,
  },
  {
    title: '备注',
    key: 'remark',
    dataIndex: 'remark',
    slotName: 'remark',
    width: 150,
  },
])
const tableColumns3 = useTableColumn([
  {
    title: '物料大类',
    key: 'bigClassName',
    dataIndex: 'bigClassName',
    width: 150,
  },
  {
    title: '物料编号',
    key: 'materialCode',
    dataIndex: 'materialCode',
    width: 150,
  },
  {
    title: '物料名称',
    key: 'materialName',
    dataIndex: 'materialName',
    width: 150,
  },
  {
    title: '规格',
    key: 'specName',
    dataIndex: 'specName',
    width: 150,
  },
  {
    title: '申购数量',
    key: 'applyNum',
    dataIndex: 'applyNum',
    width: 150,
  },
  {
    title: '库存数量',
    key: 'stockNum',
    dataIndex: 'stockNum',
    // slotName: 'stockNum',
    width: 150,
  },
  {
    title: '单位',
    key: 'unit',
    dataIndex: 'unit',
    width: 150,
  },
  {
    title: '采购部门',
    key: 'useDepartment',
    dataIndex: 'useDepartment',
    width: 150,
  },
  {
    title: '备注',
    key: 'remark',
    dataIndex: 'remark',
    slotName: 'remark',
    width: 150,
  },
  {
    title: '采购数量',
    key: 'purchaseNum',
    dataIndex: 'purchaseNum',
    slotName: 'purchaseNum',
    width: 150,
  },
  {
    title: '采购单位',
    key: 'purchaseUnit',
    dataIndex: 'purchaseUnit',
    width: 150,
  },
  // {
  //   title: '欠数',
  //   key: 'oweNum',
  //   dataIndex: 'oweNum',
  //   slotName: 'oweNum',
  //   width: 150,
  // },
  // {
  //   title: '采购公司',
  //   key: 'useCompanys',
  //   dataIndex: 'useCompanys',
  //   width: 150,
  // },
  {
    title: '单价',
    key: 'price',
    dataIndex: 'price',
    slotName: 'price',
    width: 150,
  },
  {
    title: '总价',
    key: 'amount',
    dataIndex: 'amount',
    slotName: 'amount',
    width: 150,
  },
  {
    title: '转化比例',
    key: 'convertRate',
    dataIndex: 'convertRate',
    width: 150,
  },
  {
    title: '操作',
    key: 'act',
    dataIndex: 'act',
    slotName: 'act',
    width: 80,
  },
])
const pageData = reactive<{
  nameList: any[]
  nameListqq: []
  nameListz: []
  nameLists: []
  nameLists6: []
  nameListqqq: any
  showAdd: boolean
  sideTitle: string
  dropDownData: any
  pageLoading: boolean
  rHeight: any
  dropDownDataqqq: any
  blTypeList: any[]
  xqDataList: any[]
  tqDataList: any[]
  isDetailsList: any[]
  firmList: any[]
  firmListsy: any[]
  bmListsy: any[]
  bmList: any[]
  title: any
  isShow: boolean
  firmGroupList: []
  loading: boolean
  title1: any
  loading1: boolean
  firmGroupList1: []
  title2: any
  loading2: boolean
  isDetail: boolean
  isEdit: boolean
  dzList: any[]
}>({
  isDetail: false,
  isEdit: false,
  bmList: [],
  title: '',
  isShow: true,
  firmGroupList: [],
  loading1: false,
  title1: '',
  loading: false,
  dzList: [],
  firmGroupList1: [],
  loading2: false,
  title2: '',

  nameLists: [],
  nameListz: [],
  nameListqq: [],
  nameLists6: [],
  nameListqqq: [],
  nameList: [],
  showAdd: false,
  sideTitle: '新增产品基础资料',
  dropDownData: '',
  pageLoading: false,
  rHeight: '',
  dropDownDataqqq: '',
  blTypeList: [],
  xqDataList: [],
  tqDataList: [],
  isDetailsList: [],
  firmList: [],
  firmListsy: [],
  bmListsy: [],
})

const tableColumns = useTableColumn([
  {
    title: '采购单号',
    key: 'purchaseCode',
    dataIndex: 'purchaseCode',
    width: 150,
  },
  // {
  //     title: "物料编号",
  //     key: "purchaseNeedCode",
  //     dataIndex: "purchaseNeedCode",
  //     width: 150
  // },
  {
    title: '编制日期',
    key: 'purchaseDate',
    dataIndex: 'purchaseDate',
    width: 200,
  },
  {
    title: '供应商名称',
    key: 'providerName',
    dataIndex: 'providerName',
    width: 150,
  },
  {
    title: '采购类型',
    key: 'purchaseType',
    dataIndex: 'purchaseType',
    width: 150,
  },
  {
    title: '计划交货日期',
    key: 'planDeliveryDate',
    dataIndex: 'planDeliveryDate',
    width: 150,
  },
  // {
  //     title: "物料编号",
  //     key: "updateTime",
  //     dataIndex: "updateTime",
  //     width: 150
  // },
  {
    title: '合同号',
    key: 'orderNo',
    dataIndex: 'orderNo',
    width: 150,
  },
  {
    title: '币种',
    key: 'moneyType',
    dataIndex: 'moneyType',
    width: 150,
  },
  {
    title: '采购员',
    key: 'createName',
    dataIndex: 'createName',
    width: 150,
  },
  {
    title: '付款方式',
    key: 'settlementType',
    dataIndex: 'settlementType',
    width: 150,
  },
  {
    title: '交货方式',
    key: 'logisticType',
    dataIndex: 'logisticType',
    width: 150,
  },
  {
    title: '结算公司',
    key: 'settlementCompanyName',
    dataIndex: 'settlementCompanyName',
    width: 150,
  },
  {
    title: '采购公司',
    key: 'useCompanyName',
    dataIndex: 'useCompanyName',
    width: 150,
  },
  {
    title: '采购部门',
    key: 'useDepartment',
    dataIndex: 'useDepartment',
    width: 150,
  },
  {
    title: '备注',
    key: 'remark',
    dataIndex: 'remark',
    width: 150,
  },
  {
    title: '制单人',
    key: 'createName',
    dataIndex: 'createName',
    width: 150,
  },
  {
    title: '状态',
    key: 'auditState',
    dataIndex: 'auditState',
    slotName: 'auditState',
    width: 150,
    fixed: 'right',
  },
  {
    title: '审核人',
    key: 'auditPerson',
    dataIndex: 'auditPerson',
    width: 150,
  },
  {
    title: '审核日期',
    key: 'auditDate',
    dataIndex: 'auditDate',
    width: 200,
  },
  {
    title: '修改人',
    key: 'updateName',
    dataIndex: 'updateName',
    width: 150,
  },
  {
    title: '修改日期',
    key: 'updateTime',
    dataIndex: 'updateTime',
    width: 200,
  },
  {
    title: '操作',
    key: 'id',
    slotName: 'cz',
    width: 180,
    fixed: 'right',
  },
])
function doRefreshs() {
  post({
    url: 'dwPurchase/PurchaseApply/getPage',
    data: {
      page: pagination1.page,
      size: pagination1.pageSize,

      auditState: 1,
      applyCode: pageData.dropDownDataqqq,
    },
  })
    .then(({ data, code }: any) => {
      if (code === 200) {
        tables.handleSuccess(data.list)
        pagination1.setTotalSize(data.total)
      }
    })
    .catch(console.log)
}
const selectShs = () => {
  pagination.page = 1
  doRefreshs()
}

onMounted(() => {
  // proChange(dataForm.providerName)
  pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight
  //表格的高
  if (pageData.rHeight !== undefined) {
    pageData.rHeight = pageData.rHeight

    console.log(pageData.rHeight)
  }
  window.addEventListener('resize', () => {
    pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight

    //表格的高
    if (pageData.rHeight !== undefined) {
      pageData.rHeight = pageData.rHeight
    }
  })
  // foucusUseFrim(1);
  // foucusUseFrim(2);
})

//下拉框得到焦点
const focusSel = () => {
  selCxAll({ applyCode: '' })
}
interface SettlementType {
  id: any
  uid: any
  purchaseCode: any
  purchaseDate: any
  providerId: any
  providerName: any
  purchaseType: any
  purchasePerson: any
  settlementType: any
  logisticType: any
  auditState: any
  auditPerson: any
  auditDate: any
  planDeliveryDate: any
  settlementCompanyName: any
  signAddress: any
  customName: any
  deliveryExplain: any
  useDepartment: any
  orderNo: any
  moneyType: any
  remark: any
  deleteState: any
  createName: any
  useCompany: any
  useCompanyName: any
  rejectCause: any
  zId: any
  address: any
}
const dataForm = reactive<SettlementType>({
  id: null,
  uid: '',
  purchaseCode: '',
  purchaseDate: '',
  providerId: null,
  providerName: '',
  purchaseType: '',
  purchasePerson: '',
  settlementType: '',
  logisticType: '',
  auditState: '',
  auditPerson: '',
  auditDate: '',
  planDeliveryDate: '',
  settlementCompanyName: '',
  signAddress: '',
  customName: '',
  deliveryExplain: '',
  useDepartment: '',
  orderNo: '',
  moneyType: '',
  remark: '',
  deleteState: '',
  createName: '',
  useCompany: '',
  useCompanyName: '',
  rejectCause: '',
  zId: null,
  address: "",
})

//下拉数据
const options = ref<any>(pageData.nameList)
const loading = ref(false)
const handleSearch = (value: any) => {
  if (value) {
    const ob = { applyCode: value }
    loading.value = true
    window.setTimeout(() => {
      selCxAll(ob)
      options.value = pageData.nameList
      loading.value = false
    }, 200)
  } else {
    options.value = []
  }
}
//下拉框查询
function selCxAll(val: any) {
  post({
    url: 'dwPurchase/PurchaseApply/getFieldValue',
    data: val,
  }).then(({ data, code }: any) => {
    if (code === 200) {
      console.log(data)
      // (data as string[]).splice(0, 0, "全部");
      pageData.nameList = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}

const selectSh = () => {
  pagination.page = 1
  doRefresh()
}

const auditSh = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请勾选需要审核的数据')
    return
  }
  var list: any = []
  for (let i = 0; i < gridOption.value.getSelectedRows().length; i++) {
    var ob = {}
    ob['auditState'] = 1
    ob['id'] = gridOption.value.getSelectedRows()[i].id
    list.push(ob)
    gridOption.value.getSelectedRows()[i]['firmId'] = gridOption.value.getSelectedRows()[i]['useCompany']
    gridOption.value.getSelectedRows()[i]['firmName'] = gridOption.value.getSelectedRows()[i]['useCompanyName']
    gridOption.value.getSelectedRows()[i]['unit'] = gridOption.value.getSelectedRows()[i]['purchaseUnit']
    gridOption.value.getSelectedRows()[i]['amount'] = gridOption.value.getSelectedRows()[i]['totalPrice']
  }
  Modal.confirm({
    title: '系统提示',
    content: '是否审核此订单',
    onOk() {
      post({
        url: 'dwPurchase/PurchaseOrder/setAudit',
        data: list,
      }).then((res: any) => {
        if (res.code === 200) {
          selectedRowKeys.value = []
          emitter.emit('shuaxiong')
          Message.success('审核通过')
          //保存在历史
          post({
            url: 'dwPurchase/purchasePriceDetail/insert',
            data: gridOption.value.getSelectedRows(),
          }).then((res: any) => {
            if (res.code === 200) {
              doRefresh()
            } else {
              Message.error(res.message)
            }
          })
        } else {
          Message.error(res.message)
        }
      })
    },
  })
}
const rejecteds = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请勾选需要审核的数据')
    return
  }
  visible5.value = true
  // var list: any = [];
  // for (let i = 0; i < gridOption.value.getSelectedRows().length; i++) {
  //     var ob = {};
  //     ob["auditState"] = 2
  //     ob["id"] = gridOption.value.getSelectedRows()[i].id
  //     list.push(ob)

  // }
  // Modal.confirm({
  //     title: '系统提示',
  //     content: '是否驳回订单',
  //     onOk() {
  //         post({
  //             url: "dwPurchase/PurchaseOrder/setAudit",
  //             data: list,
  //         }).then((res: any) => {
  //             if (res.code === 200) {
  //                 doRefresh()
  //                 selectedRowKeys.value = []
  //                 emitter.emit('shuaxiong')
  //                 Message.success('订单已驳回')
  //             } else {
  //                 Message.error(res.message)
  //             }
  //         })
  //     }
  // })
}

const okk1 = () => {
  var list: any = []
  for (let i = 0; i < gridOption.value.getSelectedRows().length; i++) {
    var ob = {}
    ob['auditState'] = 2
    ob['rejectState'] = 1
    ob['rejectCause'] = dataForm.rejectCause
    ob['id'] = gridOption.value.getSelectedRows()[i].id
    list.push(ob)
  }
  post({
    url: 'dwPurchase/PurchaseOrder/setAudit',
    data: list,
  }).then((res: any) => {
    if (res.code === 200) {
      Message.success('订单已驳回')
      selectedRowKeys.value = []
      dataForm.rejectCause = ''
      visible5.value = false
      doRefresh()
    } else {
      Message.error(res.message)
    }
  })
}

const auditStates = (val: any) => {
  Modal.confirm({
    title: '系统提示',
    content: '是否反审此订单',
    onOk() {
      post({
        url: 'dwPurchase/PurchaseOrder/setAudit',
        data: {
          id: Number(val.id),
          auditState: 0,
        },
      }).then((res: any) => {
        if (res.code === 200) {
          doRefresh()
          emitter.emit('shauxings')
          Message.success('反审成功')
        } else {
          Message.error(res.message)
        }
      })
    },
  })
}
// let vals = reactive({})
const editHandler = (val: any) => {
  getFirmGroup()
  focusSelz()
  // visibles.value = true
  visibles1.value = true

  // emitter.emit('xiugaiCg', val)
  // vals = val
  // dataForm.id = Number(val.id)
  // dataForm.uid = Number(val.uid)
  // dataForm.purchaseCode = val.purchaseCode
  // dataForm.purchaseDate = val.purchaseDate
  // dataForm.providerName = val.providerName
  // dataForm.providerName = val.providerName
  // dataForm.purchaseType = val.purchaseType
  // dataForm.purchasePerson = val.purchasePerson
  // dataForm.settlementType = val.settlementType
  // dataForm.logisticType = val.logisticType
  // dataForm.auditPerson = val.auditPerson
  // dataForm.planDeliveryDate = val.planDeliveryDate
  // dataForm.settlementCompanyName = val.settlementCompanyName
  // dataForm.signAddress = val.signAddress
  // dataForm.createName = val.createName
  // dataForm.deliveryExplain = val.deliveryExplain
  // dataForm.useDepartment = val.useDepartment
  // dataForm.remark = val.remark
  // dataForm.orderNo = val.orderNo
  // dataForm.moneyType = val.moneyType
  // dataForm.useCompany = val.useCompany

  for (var key in val) {
    dataForm[key] = val[key]
  }
  // proChange(dataForm.providerName)
  // dataForm.providerId = val.providerName
  //拿到此页面的详情
  dataForm.zId = val.id
  Details(val.id)
}

const Details = (val: any) => {
  post({
    url: 'dwPurchase/PurchaseOrderDetail/getList',
    data: {
      purchaseOrderId: val,
      rejectState: 0,
    },
  }).then(({ data, code }: any) => {
    if (code === 200) {
      pageData.tqDataList = data
      gridOptionsz111.value.setRowData(data)
      ckNum()
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}

const isOk = () => {
  post({
    url: 'dwPurchase/PurchaseOrder/updateList',
    data: {
      ...dataForm,
      purchaseOrderDetail: isDataLists.value,
    },
  }).then((res: any) => {
    if (res.code == 200) {
      doRefresh()
      visibles1.value = false
      isDataLists.val = []
      Message.success('修改成功')
    } else {
      Message.error(res.message)
    }
  })
}
const isOk1 = () => {
  let list = []
  for (let i = 0; i < pageData.tqDataList.length; i++) {
    var ob = {}
    ob['materialCode'] = pageData.tqDataList[i].materialCode
    ob['materialName'] = pageData.tqDataList[i].materialName
    ob['specName'] = pageData.tqDataList[i].specName
    ob['purchaseNum'] = pageData.tqDataList[i].purchaseNum
    ob['purchaseUnit'] = pageData.tqDataList[i].purchaseUnit
    ob['applyNum'] = pageData.tqDataList[i].applyNum
    ob['unit'] = pageData.tqDataList[i].unit
    ob['stockNum'] = pageData.tqDataList[i].stockNum
    ob['useDepartment'] = pageData.tqDataList[i].useDepartment
    ob['price'] = pageData.tqDataList[i].price
    ob['taxRate'] = pageData.tqDataList[i].taxRate
    ob['amount'] = pageData.tqDataList[i].amount
    ob['convertRate'] = pageData.tqDataList[i].convertRate
    ob['amount'] = pageData.tqDataList[i].amount
    ob['HistoricalPrice'] = pageData.tqDataList[i].HistoricalPrice
    ob['useCompany'] = dataForm.useCompany
    ob['bigClassName'] = pageData.tqDataList[i].bigClassName
    list.push(ob)
  }
  post({
    url: 'dwPurchase/PurchaseOrder/updateList',
    data: {
      ...dataForm,
      purchaseOrderDetail: list,
      // needList: selectedRowKeys.value
    },
  }).then((res: any) => {
    if (res.code === 200) {
      doRefresh()
      selectedRowKeys.value = []

      Message.success({
        content: '保存成功!',
        duration: 5000,
      })
      visibles1.value = false
    } else {
      Message.error({
        content: res.message,
        duration: 5000,
      })
    }
  })
}

const isCancel = () => {
  visibles1.value = false
}

const deleteHandler = () => {
  if (selectedRowKeys.value.length === 0) {
    return
  }
  Modal.confirm({
    title: '系统提示',
    content: '确认删除选中的数据?',
    onOk() {
      post({
        url: 'dwPurchase/PurchaseOrder/delete',
        data: selectedRowKeys.value,
      }).then(({ code, data, message }: any) => {
        if (code === 200) {
          Message.success({
            content: '删除成功',
            duration: 5000,
          })
        } else {
          Message.error({
            content: message,
            duration: 5000,
          })
        }
        doRefresh()
      })
    },
  })
}

//下拉框得到焦点
const focusSelx = () => {
  selCxAllx({ settlementName: '' })
}
//下拉数据
const optionsx = ref<any>(pageData.nameList)
const loadingx = ref(false)
const handleSearchx = (value: any) => {
  if (value) {
    const ob = { settlementName: value }
    loadingx.value = true
    window.setTimeout(() => {
      selCxAllx(ob)
      optionsx.value = pageData.nameList
      loadingx.value = false
    }, 200)
  } else {
    optionsx.value = []
  }
}
//下拉框查询
function selCxAllx(val: any) {
  post({
    url: 'dwPurchase/SettlementType/getFieldValue',
    data: val,
  }).then(({ data, code }: any) => {
    if (code === 200) {
      console.log(data)
      // (data as string[]).splice(0, 0, "全部");
      pageData.nameList = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}

//下拉框得到焦点
const focusSelqq = () => {
  selCxAllqq({ deliveryType: '' })
}
//下拉数据
const optionsqq = ref<any>(pageData.nameListqq)
const loadingqq = ref(false)
const handleSearchqq = (value: any) => {
  if (value) {
    const ob = { deliveryType: value }
    loadingqq.value = true
    window.setTimeout(() => {
      selCxAllqq(ob)
      optionsqq.value = pageData.nameListqq
      loadingqq.value = false
    }, 200)
  } else {
    optionsqq.value = []
  }
}
//下拉框查询
function selCxAllqq(val: any) {
  post({
    url: 'dwPurchase/LogisticType/getFieldValue',
    data: val,
  }).then(({ data, code }: any) => {
    if (code === 200) {
      console.log(data)
      // (data as string[]).splice(0, 0, "全部");
      pageData.nameListqq = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}

//下拉框得到焦点
const focusSelz = () => {
  selCxAllz({ providerName: '' })
}
//下拉数据
const optionsz = ref<any>(pageData.nameListz)
const loadingz = ref(false)
const handleSearchz = (value: any) => {
  if (value) {
    const ob = { providerName: value }
    loadingz.value = true
    selCxAllz(ob)
    optionsz.value = pageData.nameListz
    loadingz.value = false
  } else {
    optionsz.value = []
  }
}
//下拉框查询
function selCxAllz(val: any) {
  post({
    url: 'dwPurchase/Provider/getFieldValue',
    data: val,
  }).then(({ data, code }: any) => {
    if (code === 200) {
      // (data as string[]).splice(0, 0, "全部");
      pageData.nameListz = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}

//下拉框得到焦点
const focusSels = () => {
  selCxAlls({ purchaseType: '' })
}
//下拉数据
const optionss = ref<any>(pageData.nameLists)
const loadings = ref(false)
const handleSearchs = (value: any) => {
  if (value) {
    const ob = { purchaseType: value }
    loadings.value = true
    window.setTimeout(() => {
      selCxAlls(ob)
      optionss.value = pageData.nameLists
      loadings.value = false
    }, 200)
  } else {
    optionss.value = []
  }
}
//下拉框查询
function selCxAlls(val: any) {
  post({
    url: 'dwPurchase/PurchaseType/PurchaseTypeValue',
    data: val,
  }).then(({ data, code }: any) => {
    if (code === 200) {
      console.log(data)
      // (data as string[]).splice(0, 0, "全部");
      pageData.nameLists = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}

//下拉框得到焦点
const focusSel6 = () => {
  selCxAlls6({ purchaseCode: '', auditState: 0 })
}
//下拉数据
const optionss6 = ref<any>(pageData.nameLists6)
const loadings6 = ref(false)
const handleSearch6 = (value: any) => {
  if (value) {
    const ob = { purchaseCode: value, auditState: 0 }
    loadings6.value = true
    window.setTimeout(() => {
      selCxAlls6(ob)
      optionss6.value = pageData.nameLists6
      loadings6.value = false
    }, 200)
  } else {
    optionss6.value = []
  }
}
//下拉框查询
function selCxAlls6(val: any) {
  post({
    url: 'dwPurchase/PurchaseOrder/getFieldValue',
    data: val,
  }).then(({ data, code }: any) => {
    if (code === 200) {
      console.log(data)
      // (data as string[]).splice(0, 0, "全部");
      pageData.nameLists6 = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}
const headerShow = ref<boolean>(true)

//下拉框得到焦点
const focusSelqqq = () => {
  selCxAllqqq({ applyCode: '' })
}
//下拉数据
const optionsqqq = ref<any>(pageData.nameListqqq)
const loadingqqq = ref(false)
const handleSearchqqq = (value: any) => {
  if (value) {
    const ob = { applyCode: value }
    loadingqqq.value = true
    window.setTimeout(() => {
      selCxAllqqq(ob)
      optionsqqq.value = pageData.nameListqqq
      loadingqqq.value = false
    }, 200)
  } else {
    optionsqqq.value = []
  }
}
//下拉框查询
function selCxAllqqq(val: any) {
  post({
    url: 'dwPurchase/PurchaseApply/getFieldValue',
    data: val,
  }).then(({ data, code }: any) => {
    if (code === 200) {
      console.log(data)
      // (data as string[]).splice(0, 0, "全部");
      pageData.nameListqqq = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}

const focusBl = () => {
  post({
    url: 'dict/dictTypeDetail/getListByCodeType?codeType=14',
  }).then((res: any) => {
    if (res.code == 200) {
      pageData.blTypeList = res.data
    }
  })
}
// 修改弹窗删除物料
const delRow = () => {
  if (selectedRowKeys1.value.length == 0) {
    Message.warning('请先勾选')
    return
  }
  pageData.tqDataList = pageData.tqDataList.filter(function (o: any) {
    return selectedRowKeys1.value.includes(o['id'])
  })
}
const addXqiu = () => {
  formRef.value?.validate().then((err: any) => {
    if (!err) {
      if (isDataLists.value.length == 0) {
        Message.error('请提取申购单')
        return
      } else {
        dataForm.id = null
        pageData.xqDataList.forEach(function (o: any) {
          o['id'] = undefined
        })
        post({
          url: 'dwPurchase/PurchaseOrder/insertList',
          data: {
            ...dataForm,
            // purchaseOrderDetail: isDataLists.value
            purchaseApplyDetail: pageData.xqDataList,
          },
        }).then((res: any) => {
          if (res.code === 200) {
            formRef.value?.resetFields()
            isDataLists.value = []
            table.dataList = []
            for (let item in dataForm) {
              dataForm[item] = ''
            }
            Message.success({
              content: '新增成功',
              duration: 5000,
            })
          } else {
            Message.error({
              content: res.message,
              duration: 5000,
            })
          }
        })
      }
    }
  })
}
const delQk = () => {
  formRef.value?.resetFields()
  isDataLists.value = []
  for (let item in dataForm) {
    dataForm[item] = ''
  }
}
const visible1 = ref(false)
//查看详情按钮
const cxDetails = (record: any) => {
  visible1.value = true
  post({
    url: 'dwPurchase/PurchaseOrderDetail/getList',
    data: {
      purchaseOrderId: record['id'],
      rejectState: 0,
    },
  }).then(({ data, code }: any) => {
    if (code === 200) {
      pageData.isDetailsList = data
      ckNum3()
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}
//拿到所有公司
// const foucusUseFrim = (num: any) => {
//     let ob = {}
//     if (num == 1) {
//         ob['firmName'] = ""
//         ob['department'] = ""
//         // ob['firmTypeId'] = ""
//     }
//     if (num == 2) {
//         ob['firmName'] = ""
//         ob['department'] = ""
//         // ob['firmTypeId'] = ""

//     }

//     if (num == 3) {
//         if (dataForm.useCompany !== '' && dataForm.useCompany !== undefined) {
//             let list = pageData.firmListsy.filter(function (o: any) {
//                 return o['id'] == dataForm.useCompany
//             })
//             let lists = pageData.firmList.filter((o: any) => {
//                 return o['id'] == dataForm.settlementCompanyName
//             })
//             // dataForm.useCompany = list[0]['firmName']
//             // dataForm.settlementCompany = lists[0]['firmName']
//             ob['firmName'] = list[0]['firmName']
//             ob['department'] = list[0]['department']
//             ob['firmTypeId'] = list[0]['firmTypeId']

//         } else {
//             Message.warning({
//                 content: "请先选择采购公司",
//                 duration: 5000
//             })
//         }

//     }

//     getFrimList(ob, num)

// }
const options2 = ref(pageData.firmList)
const loading2 = ref(false)

const handleSearch2 = (value: any) => {
  if (value) {
    loading2.value = true

    options2.value = pageData.firmList
    loading2.value = false
  } else {
    options2.value = []
  }
}
// function getFrimList(ob: any, nums: any) {

//     post({
//         url: "org/firmGroup/getFirmInfoByMap",
//         data: ob
//     }).then((result: any) => {
//         if (result.code === 200) {
//             if (nums == 1) {
//                 pageData.firmList = result.data
//             }
//             if (nums == 2) {
//                 pageData.firmListsy = result.data
//             }
//             if (nums == 3) {
//                 pageData.bmListsy = result.data
//             }
//         } else {
//             Message.error(result.message)
//         }

//     })
// }

const gridOption = ref()
const gridReady = (params: any) => {
  gridOption.value = params.api
}
const defaultColDef = {
  sortable: true,
  resizable: true,
  filter: true,
}
let tc: any[] = tableColumns.map((o) => {
  let obj = {
    headerName: o.title,
    field: o.key,
    pinned: o['fixed'],
    tooltipField: o.key,
  }
  if (o.slotName === 'cz') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'right'
    obj['width'] = 150
    obj['cellRenderer'] = {
      template: `
                    <a-space>
                        <el-button v-if="(isDtas.auditState == 0) && e" style="color:#165dff;" link
                                @click="a1">
                                修改
                            </el-button>
                            <el-button v-if="(isDtas.auditState != 0) && e2" disabled type="info" link>
                                修改
                            </el-button>
                            <el-button style="color:#165dff;" link @click="a2" v-if="f">
                                详情
                            </el-button>
                    </a-space>

                    `,
      setup(props: any) {
        const isDtas = ref(props.params.data)
        const a1 = () => {
          editHandler(props.params.data)
        }
        const a2 = () => {
          cxDetails(props.params.data)
        }
        return {
          e: pageData.isEdit,
          e2: pageData.isEdit,
          f: pageData.isDetail,
          a1,
          a2,
          isDtas,
        }
      },
    }
  }
  if (o.slotName === 'auditState') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'right'
    obj['width'] = 120
    obj['cellRenderer'] = {
      template: `<el-tag v-if="isDatas.auditState == 0" type="warning"
                              >待审核
                            </el-tag>
                            <el-tag v-if="isDatas.auditState == 1" type="success">审核通过
                            </el-tag>
                            <el-tag v-if="isDatas.auditState == 3" type="info">完结
                        </el-tag>
                            `,
      setup(props: any) {
        const isDatas = ref(props.params.data)
        return {
          isDatas,
        }
      },
    }
  }
  return obj
})

let a = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
]
tc = a.concat(tc)

const gridOptionsz111 = ref()
const gridReadysz111 = (params: any) => {
  gridOptionsz111.value = params.api
}
const defaultColDefsz111 = {
  sortable: true,
  resizable: true,
  filter: true,
  flex: 1,
}
let tcsz111: any[] = tableColumns3.map((o) => {
  let obj = {
    headerName: o.title,
    field: o.key,
    pinned: o['fixed'],
    tooltipField: o.key,
  }
  if (o.slotName === 'purchaseNum') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['cellRenderer'] = {
      template: `
                    <a-input-number v-model="isDtas.purchaseNum" @change="a" class="input-demo bacClass" :min="0"
                            :max="10000000000000000000" />
                    `,
      setup(props: any) {
        const isDtas = ref(props.params.data)
        if (props.params.data.purchaseNum == '' || props.params.data.purchaseNum == null) {
          props.params.data.purchaseNum = 0
        }
        const a = () => {
          numchange(props.params.data)
        }
        return {
          a,
          isDtas,
        }
      },
    }
  }
  if (o.slotName === 'stockNum') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['cellRenderer'] = {
      template: `
                    <a-input-number v-model="isDtas.stockNum" class="input-demo bacClass" :min="0"
                            :max="10000000000000000000" />
                    `,
      setup(props: any) {
        const isDtas = ref(props.params.data)
        return {
          isDtas,
        }
      },
    }
  }
  if (o.slotName === 'convertRate') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['cellRenderer'] = {
      template: `<a-input-number v-model="isDtas.convertRate" class="input-demo bacClass" :min="0" :max="10000000000000000000" />`,
      setup(props: any) {
        const isDtas = ref(props.params.data)
        return {
          isDtas,
        }
      },
    }
  }
  if (o.slotName === 'price') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['cellRenderer'] = {
      template: `<a-input-number @change="a" v-model="isDtas.price" class="input-demo bacClass" :min="0" />`,
      setup(props: any) {
        const isDtas = ref(props.params.data)
        if (props.params.data.price == '' || props.params.data.price == null) {
          props.params.data.price = 0
        }
        const a = () => {
          numchange(props.params.data)
        }
        return {
          a,
          isDtas,
        }
      },
    }
  }
  if (o.key === 'amount') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['cellRenderer'] = {
      template: ` <div>{{isDtas.price*isDtas.purchaseNum}}</div>`,
      setup(props: any) {
        const isDtas = ref(props.params.data)
        return {
          isDtas,
        }
      },
    }
  }
  if (o.slotName === 'remark') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['cellRenderer'] = {
      template: `
                    <a-input class="bacClass" v-model="isDtas.remark" />
                    `,
      setup(props: any) {
        const isDtas = ref(props.params.data)
        return {
          isDtas,
        }
      },
    }
  }
  if (o.slotName === 'act') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'right'
    obj['width'] = 80
    obj['cellRenderer'] = {
      template: `<el-button style="color:#165dff;" link @click="b">驳回</el-button>`,
      setup(props: any) {
        const b = () => {
          overrule()
        }
        return {
          b,
        }
      },
    }
  }
  return obj
})

let asz111 = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
]
tcsz111 = asz111.concat(tcsz111)
const localeText1: any = ref(localeText)
const huiche = () => {
  selectSh()
}
const pagingList1: any = ref(pagingList)

const getFirmGroup = () => {
  post({
    url: 'org/baCompany/getTreeCompanyByUser',
    data: {},
  }).then(({ code, data }) => {
    if (code === 200) {
      pageData.firmGroupList = data
      pageData.firmGroupList1 = data
    }
  })
}

let casOb = ref()
const casOb1 = ref()
//公司改变
const cascaderChange = (event: any, val: any) => {
  // dataForm.department = null
  //拿到选中的这个节点数组
  setTimeout(function () {
    if (casOb.value.selectViewValue.length != 0) {
      pageData.title = slicing(casOb.value.selectViewValue[0]['label'])
      dataForm.useCompanyName = slicing(casOb.value.selectViewValue[0]['label'])
    }
  }, 100)
  ckNum()
  getBmGroup(val)
  dataForm.useDepartment = ''
  pageData.bmList = []
}
//部门改变
const cascaderChange1 = (val: any) => {
  //拿到选中的这个节点数组
  setTimeout(function () {
    if (casOb1.value.selectViewValue.length != 0) {
      pageData.title1 = slicing(casOb1.value.selectViewValue[0]['label'])
      dataForm.useDepartment = slicing(casOb1.value.selectViewValue[0]['label'])
    }
  }, 100)
}
// 获取部门列表
const getBmGroup = (val: any) => {
  post({
    url: 'org/baCompany/getDepartmentTree?companyId=' + val,
  }).then((result) => {
    if (result.code === 200) {
      pageData.bmList = result.data
    }
  })
}
const casOb2 = ref()
//公司改变
const cascaderChange2 = (event: any, val: any) => {
  // dataForm.department = null
  //拿到选中的这个节点数组
  setTimeout(function () {
    if (casOb2.value.selectViewValue.length != 0) {
      pageData.title2 = slicing(casOb2.value.selectViewValue[0]['label'])
      dataForm.settlementCompanyName = slicing(casOb2.value.selectViewValue[0]['label'])
    }
  }, 100)
  // getBmGroup1(val)
}
//库存数量
const ckNum = () => {
  post({
    url: '/wms/ironwareStockSummary/getStockNumProcurement',
    data: pageData.tqDataList.map((item: any) => {
      return {
        materialCode: item.materialCode,
        companyId: dataForm.useCompany,
        materialName: item.materialName,
      }
    }),
  }).then((res: any) => {
    const { data } = res
    pageData.tqDataList.map((item: any, index: any) => {
      if (item.materialCode == data[index].materialCode) {
        item.stockNum = data[index].stockNum
      }
    })
  })
}
const proChange = () => {
  let list = pageData.nameListz.filter(function (o: any) {
    return o['providerId'] == dataForm.providerId
  })
  dataForm.providerName = list[0]['providerName']
}
//详情中的 库存数量
const ckNum3 = () => {
  post({
    url: '/wms/ironwareStockSummary/getStockNumProcurement',
    data: pageData.isDetailsList.map((item: any) => {
      return {
        materialCode: item.materialCode,
        companyId: gridOption.value.getSelectedRows()[0].useCompany,
        materialName: item.materialName,
      }
    }),
  }).then((res: any) => {
    const { data } = res
    pageData.isDetailsList.map((item: any, index: any) => {
      if (item.materialCode == data[index].materialCode) {
        item.stockNum = data[index].stockNum
      }
    })
  })
}
const numchange = (val: any) => {
  var numCount = val.price * val.purchaseNum
  pageData.tqDataList.map((o: any) => {
    if (o.id == val.id) {
      o.amount = numCount
    }
  })
}

const visible5 = ref(false)
const visible6 = ref(false)
const overrule = () => {
  if (pageData.tqDataList.length == 1) {
    Message.error('单据中至少保留一条物料信息')
    return
  } else {
    visible6.value = true
  }
}
const okk = () => {
  post({
    url: '/dwPurchase/PurchaseOrderDetail/audit',
    data: {
      // list1: gridOption.value.getSelectedRows(),
      list2: gridOptionsz111.value.getSelectedRows(),
      rejectState: 1,
      rejectCause: dataForm.rejectCause,
    },
  }).then((res: any) => {
    if (res.code === 200) {
      const selectedData = gridOptionsz111.value.getSelectedRows()
      gridOptionsz111.value.applyTransaction({ remove: selectedData })
      Message.success('订单已驳回')
      dataForm.rejectCause = ''
      visible6.value = false
      Details(dataForm.zId)
    } else {
      Message.error(res.message)
    }
  })
}

// 送货地址下拉框
const focusAddress = () => {
  getAddressList('')
}
const searchAddress = (value: any) => {
  if (value) {
    loading.value = true
    getAddressList(value)
    options.value = pageData.dzList
    loading.value = false
  } else {
    options.value = []
  }
}
const getAddressList = (val: any) => {
  post({
    url: 'dict/dictTypeDetail/getList',
    data: {
      codeType: 35,
      detailName: val,
    },
  }).then(({ code, data }: any) => {
    if (code == 200) {
      pageData.dzList = data
    } else {
      Message.error({
        content: '查询失败',
        duration: 5000,
      })
    }
  })
}

const permissionStore = usePermission()
if (permissionStore.hasPermisson('cgdsh.xg1')) {
  pageData.isEdit = true
}
if (permissionStore.hasPermisson('cgdsh.xq1')) {
  pageData.isDetail = true
}
</script>

<style lang="less" scoped>
.xqdxx {
  display: flex;
}

:deep(.arco-table-td-content) {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>